package Test;

import java.util.Stack;

/**
 * @author shy_black
 * @date 2019/3/8 17:51
 * @Description:
 */

public class 括号匹配 {
    public static void main(String[] args)  {
        String A  = "())";
        System.out.println(chkParenthesis(A,8));
    }

    public static boolean chkParenthesis(String A, int n)  {
        if(n%2 == 1)
            return false;


        Stack<Character> s = new Stack<>();
        char[] str = A.toCharArray();
        int i = 0;
        while(i < str.length){
            if(str[i] =='(') {
                s.push(str[i]);
            }else if (str[i] == ')') {
                if(!s.isEmpty() && '(' == s.peek()) {
                    s.pop();
                }else
                    return false;
            }else
                return false;
            i++;
        }
        if(s.isEmpty())
            return true;
        else
            return false;
    }

}